



//
//  AdressBook.m
//  04-集合2-DIctionary
//
//  Created by dllo on 16/7/7.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "AdressBook.h"

@implementation AdressBook
- (instancetype)initWithDictionary:(NSMutableDictionary *)dicrionary {
    self = [super init];
    if (self) {
        _mutableDicOfContact = dicrionary;
    }
    return self;
}
// 添加联系人
- (void)addContact:(Contact *)contact {
    if (contact.name.length > 0 && contact.phoneNumber.length > 0) {
        
        NSMutableArray *arrOfContact = [self.mutableDicOfContact objectForKey:contact.groupName];
        if (arrOfContact == nil) {
            arrOfContact = [NSMutableArray arrayWithObject:contact];
            [self.mutableDicOfContact setObject:arrOfContact forKey:contact.groupName];
        } else {
            [arrOfContact addObject:contact];
    }
        NSLog(@"添加成功");
        } else {
        NSLog(@"添加失败");
    }
}
// 删除某个联系人(根据姓名删除相应联系人)
- (void)removeContact:(Contact *)contact{
}
//移除分组的联系人
- (void)removeGroupName:(NSString *)groupName {
    [self.mutableDicOfContact removeObjectForKey:groupName];
}
- (void)removeContactOfName:(NSString *)name{
    NSString *keyOfGroupName = [[name substringToIndex:1] capitalizedString];
    NSMutableArray *arrOfGroupName = [self.mutableDicOfContact objectForKey:keyOfGroupName];
    for (Contact *contact in arrOfGroupName) {
        if ([contact.name isEqualToString:name]) {
            [arrOfGroupName removeObject:contact];
        }
    }
}
@end
